<?php
	include 'ZionHeader.inc';
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HTML>
<head>
<LINK href="test.css" rel="stylesheet" type="text/css">
</head>
<!-- <script type="text/JavaScript" src="accountCreateAjax.js"></script> -->
<script type="text/JavaScript">


function Validate()
{
    var pw1 = document.registration_form.password1.value;
    var pw2 = document.registration_form.passwordReType.value;

    if (document.registration_form.fName.value == '') 
    {
        alert('Please fill in your First Name!');
        return false;
    }
    if (document.registration_form.lName.value == '') 
    {
        alert('Please fill in your Last Name!');
        return false;
    }
    if (document.registration_form.username.value == '') 
    {
        alert('Please fill in your desired username!');
        return false;
    }
    if (pw1 == '') 
    {
       alert('Please fill in your desired password!');
      return false;
    }
    if (pw2 == '') 
    {
       alert('Please fill in your password again for confirmation!');
      return false;
    }
    if ( pw1 != pw2 ) 
    {
        alert("The two passwords are not identical! "+
        "Please enter the same password again for confirmation");
        return false;
    }

}

function displayOptions(flag)
{
var DealerOnly = document.getElementById('dealerOnly');
var DealerOnly2 = document.getElementById('dealerOnly2');
var DealerOnly3 = document.getElementById('dealerOnly3');
var DealerOnly4 = document.getElementById('dealerOnly4');
var DealerOnlyDiv = document.getElementById('dealerOnlyDiv');

    if(flag)
    {
        DealerOnly.style.display = 'inline-block';
        DealerOnly2.style.display = 'inline-block';
        DealerOnly3.style.display = 'inline-block';
        DealerOnly4.style.display = 'inline-block';
    }
    else
    {
		DealerOnly.style.display = 'none';
        DealerOnly2.style.display = 'none';
        DealerOnly3.style.display = 'none';
        DealerOnly4.style.display = 'none';
    }
	
    return false;
}

</script>

<?php

include 'DatabaseConnect.inc';

$username = $_SESSION['UName'];
//$accounttype = $_SESSION['AType'];


$query = "SELECT * FROM User WHERE LoginID = '$username'";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

if($row['PhoneNumber'])
{
	$pnumber = $row['PhoneNumber'];
	$punumber1 = substr($pnumber, 0, 3);
	$punumber2 = substr($pnumber, 3, 3);
	$punumber3 = substr($pnumber, 6, 4);
}

if($row['Street_Num'] && $row['Road'])
{
	$address = $row['Street_Num'].$row['Road'];
}


$regQuery = "SELECT * FROM RegisteredUser WHERE LoginID = '$username'";
$regResult = mysql_query($regQuery);
$regRow = mysql_fetch_array($regResult);


mysql_close();

?>

<BODY>

<center><div class="ex">

<h1> Edit Profile </h1>

<form action="updateExistingAccount.php" method="post" name="registration_form" onsubmit="return Validate();" >
<div align="left">
<UL>
	<!--
   <li class="one">Account type:
   </li>
        <li>
        User: <input type="radio" name="acctType" value="R" onclick="displayOptions(false)">
        Dealer: <input type="radio" name="acctType" value="D" onclick="displayOptions(true)" checked>
		</li>
   </li>
   -->
   <li class="one">
       First Name*:
	   </li>
	   <li>
        <input type="text" name="fName" value="<?if(isset($regRow['FName'])){echo $regRow['FName'];}?>" />
    </li>
    <li class="one">
        Middle Initial:
		</li>
		<li>
        <input type="text" name="mInitial" size="1" maxlength="1"/ value="<?if(isset($regRow['MInitial'])){echo $regRow['MInitial'];}?>">
    </li>
    <li class="one">
        Last Name*:
		</li>
		<li>
        <input type="text" name="lName" value="<?if(isset($regRow['LName'])){echo $regRow['LName'];}?>"/>
    </li>
    <li class="one">
        Address:
		</li>
		<li>
        <input type="text" name="address" value="<?if($address){echo $address;}?>"/>  Ex:(123 streetname) 
    </li>
	<li class="one">
        City:
		</li>
		<li>
        <input type="text" name="city" value="<?if($row['City']){echo $row['City'];}?>"/>
    </li>
    <li class="one">
        State:
		</li>
		<li>
        <input type="text" name="state" size="2" maxlength="2" value="<?if($row['State']){echo $row['State'];}?>" />
    </li>
    <li class="one">
        Zip:
		</li>
		<li>
        <input type="text" name="zip" size="5" maxlength="5" value="<?if($row['Zip_Code']){echo $row['Zip_Code'];}?>"/>
    </li>
    <li class="one">
        Country:
		</li>
		<li>
        <input type="text" name="country" value="<?if($row['Country']){echo $row['Country'];}?>"/>
    </li>
    <li class="one">
        Phone Number:
		</li>
		<li>
        (<input type="text" name="phone1" size="3" maxlength="3" value="<?if($punumber1){echo $punumber1;}?>"/>) -
            <input type="text" name="phone2" size="3" maxlength="3" value="<?if($punumber2){echo $punumber2;}?>"/>-
            <input type="text" name="phone3" size="4" maxlength="4" value="<?if($punumber3){echo $punumber3;}?>"/>
    </li>
    <li class="one">
        E-Mail:</td>
		</li>
		<li>
        <input type="text" name="eMail" value="<?if($row['Email']){echo $row['Email'];}?>"/>
    </li>
    <li class="one">
        Username*:
		</li>
		<li>
        <input type="text" name="username" value="<?if($row['LoginID']){echo $row['LoginID'];}?>"/>
    </li>
    <li class="one">
        Password*:
		</li>
		<li>
        <input type="password" name="password1" />
    </li>
    <li class="one">
       Re-type Password*:
      </li>   
	  <li><input type="password" name="passwordReType" /> 
    </li>
    <li class="two" id="dealerOnly">
		Description:
		</li>
		<li id="dealerOnly2">
        <input type="text" name="Descript"/>
		</li>
    </li>
    <li class="two" id="dealerOnly3">
		URL:
		</li>
		<li id="dealerOnly4">
        <input type="text" name="URL"/>
    </li>
    <li class="mid">
        <input type="submit" value="Continue"/>
    </li>
    
</UL>
</div>
</form>
* Required
<br />
<br />
<a href="index.php">Return to Index</a>

</div></center>

</BODY>
</HTML>

<?php

$accounttype =$_SESSION['AType'];

if($accounttype == 'D')
{
	echo "<script language=javascript>displayOptions(true)</script>";
}
else
{
	echo "<script language=javascript>displayOptions(false)</script>";	
} 

?>